﻿using System;
using System.IO.IsolatedStorage;

namespace Skyper.Phone.Model {
	public class SkypeConfig {
		#region Property
		public String Hostname {
			get {
				if (!IsolatedStorageSettings.ApplicationSettings.Contains("Hostname")) {
					return "http://localhost:6789/";
				}
				return IsolatedStorageSettings.ApplicationSettings["Hostname"] as String;
			}
			set {
				if (String.IsNullOrEmpty(value)) {
					if (IsolatedStorageSettings.ApplicationSettings.Contains("Hostname")) {
						IsolatedStorageSettings.ApplicationSettings.Remove("Hostname");
					}
				} else { 
					IsolatedStorageSettings.ApplicationSettings["Hostname"] = value;
				}
			}
		}
		public String Password {
			get {
				if (!IsolatedStorageSettings.ApplicationSettings.Contains("Password")) {
					return String.Empty;
				}
				return IsolatedStorageSettings.ApplicationSettings["Password"] as String;
			}
			set {
				if (String.IsNullOrEmpty(value)) {
					if (IsolatedStorageSettings.ApplicationSettings.Contains("Password")) {
						IsolatedStorageSettings.ApplicationSettings.Remove("Password");
					}
				} else {
					IsolatedStorageSettings.ApplicationSettings["Password"] = value;
				}
			}
		}
		public Boolean Remmember {
			get {
				if (!IsolatedStorageSettings.ApplicationSettings.Contains("Remmember")) {
					return false;
				}
				Object value = IsolatedStorageSettings.ApplicationSettings["Remmember"];

				if (value == null){
					return false;
				}
				if (!(value is Boolean)) {
					return false;
				}
				return (Boolean)value;
			}
			set {
				IsolatedStorageSettings.ApplicationSettings["Remmember"] = value;
				if (!value) {
					this.Password = String.Empty;
					this.Hostname = String.Empty;
				}
			}
		}
		#endregion
	}
}
